<template>
	<view class="">
		<view class="container">
			<view  class="searchBox">
				<!-- #ifdef MP-WEIXIN -->
				
				<view >
					<view class="titleBar1">
						<u-search class="search1" bg-color="#F7F8FA" placeholder="搜索你想要的工人" v-model="keyword" 
							:show-action="true" action-text="搜索" :animation="true">
						</u-search>
					</view>
				</view>
				
				<!-- #endif  -->
				<!-- #ifdef H5 -->
				<view class="titleBar">
					<u-search class="search" bg-color="#F7F8FA" placeholder="搜索你想要的工人" v-model="keyword" 
						:show-action="true" action-text="搜索" :animation="true">
					</u-search>
				</view>
				<!-- #endif -->
				<view class="u-m-p-50">
					<view class="u-demo-area u-flex u-row-center">
						<pickerAddress class="addr" @change="change">{{city}}
							<u-icon color="rgb(192, 196, 204)" class="icons" name="arrow-down"></u-icon>
						</pickerAddress>
						<u-dropdown :close-on-click-mask="mask" ref="uDropdown" :activeColor="activeColor"
							:borderBottom="borderBottom">
							<u-dropdown-item></u-dropdown-item>
							<u-dropdown-item @change="change1" v-model="value2" title="分类" :options="options2">
							</u-dropdown-item>
							<u-dropdown-item title="工种">
								<view class="slot-content">
									<view class="item-box">
										<view class="item" :class="[item.active ? 'active' : '']" @tap="tagClick(index)"
											v-for="(item, index) in list1" :key="index">
											{{item.label}}
										</view>
									</view>
									<u-button type="primary" @click="closeDropdown">确定</u-button>
								</view>
							</u-dropdown-item>
							<u-dropdown-item @change="change1" v-model="value2" title="其他" :options="options1">
							</u-dropdown-item>
						</u-dropdown>
					</view>
				</view>

			</view>
			<view v-show="showBox">
				<u-empty v-if="list.length==0" text="暂无数据" mode="list"></u-empty>
			</view>
			

			<!-- #ifdef MP-WEIXIN -->
			<view :style="{'margin-top':92+'px'}" class="list">
				<myitem :list="list" />
			</view>

			<!-- #endif -->
			<!-- #ifdef H5 -->
			<view :style="{'margin-top':'80px'}" class="list">
				<myitem :list="list" />
			</view>
			
			<!-- #endif -->
			
			<u-loadmore v-show="showBox" :status="status" icon-type="flower" margin-bottom="30" />
		</view>



	</view>
</template>

<script>
	import pickerAddress from '@/components/citys/pickerAddress.vue'
	import myitem from "@/components/list/gdzg.vue";
	export default {
		components: {
			pickerAddress,
			myitem
		},
		data() {
			return {
				enable: true,
				page: 1,
				limit: 5,
				status: 'loadmore',
				list: [],
				showBox: false,
				
				keyword: '',
				addr: true,
				city: '地区',
				value2: '2',
				mask: true,
				options1: [{
						label: '最新',
						value: 1
					},
					{
						label: '实名',
						value: 2,
					},
					{
						label: '证书',
						value: 3,
					},
					{
						label: '其他',
						value: 4
					}
				],
				options2: [{
						label: '团队',
						value: 1,
					},
					{
						label: '个人',
						value: 2,
					},
					{
						label: '施工队',
						value: 3,
					},
					{
						label: '外包团队',
						value: 4,
					}
				],
				list1: [{
						label: '琪花瑶草',
						active: true,
					},
					{
						label: '清词丽句',
						active: false,
					},
					{
						label: '宛转蛾眉',
						active: false,
					},
					{
						label: '煦色韶光',
						active: false,
					},
					{
						label: '鱼沉雁落',
						active: false,
					},
					{
						label: '章台杨柳',
						active: false,
					},
					{
						label: '霞光万道',
						active: false,
					}
				],
				borderBottom: false,
				activeColor: '#2979ff'
			}
		},
		// 在对应的show和hide页面生命周期中打开或关闭监听
		onShow() {
			this.enable = true;
			this.city = uni.getStorageSync('addr')
		},
		onHide() {
			this.enable = false
		},
		onLoad(e) {
			uni.setNavigationBarTitle({
			　　title:e.name
			})
			this.getList();
		},
		//下拉
		onPullDownRefresh() {
			this.showBox = false;
			this.page = 1
			this.list = []
			this.getList()
		},
		//下拉
		onReachBottom() {
			//避免多次触发
			if (this.status == 'loading' || this.status == 'nomore') {
				return;
			}
			this.getList()
		},
		
		methods: {

			async getList() {
				const res = await this.$myRequest({
					url: '/app/news/newsList',
					method: "POST",
					data: {
						"orgId": "1",
						"page": this.page,
						"limit": this.limit,
						"newsType": "news"
					}
				})
				console.log(res);
				if (res.data.code == 0) {
					this.showBox = true;
					let data = res.data.page.list;
					if (data.length < this.limit) {
						this.status = "nomore"
					} else {
						this.page = this.page + 1
						this.status = "loadmore"
					}
					this.list = this.list.concat(data)
					uni.stopPullDownRefresh();

				}

			},
			change(data) {
				this.city = data.data[2]
				// this.city = data.data.join('')
			},
			change1(index) {
				// this.addr = !this.addr
				this.$u.toast(`点击了第${index}项`);
			},

			closeDropdown() {
				this.$refs.uDropdown.close();
			},
			tagClick(index) {
				this.list[index].active = !this.list[index].active;
			},

		}
	}
</script>
<style>
	page {
		background: #EFEFEF;
	}
</style>
<style scoped lang="scss">
	
	.searchBox {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		background: #FFFFFF;
		/* #ifdef H5 */
		top: 44px;
		/* #endif */
		z-index: 4;
		.titleBar1{
			width: 95%;
			margin: 10px auto 0 auto;
			// display: flex;
			// align-items: center;
			// justify-content: center;
			// .search1{
			// 	width: 95%;
				
			// }
		}

		.titleBar {
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.search {
			height: 100%;
			width: 94%;
			padding: 0 3%;
			background: #FFFFFF;
		}
		
	}

	.u-m-p-50 {
		height: 40px;
	}


	.u-row-center {
		position: relative;
		z-index: 2;
		background: #FFFFFF;

		.addr {
			position: absolute;
			left: 0;
			width: 25%;
			height: 80rpx;
			line-height: 80rpx;
			z-index: 999;
			background: #FFFFFF;
			text-align: center;
			color: rgb(96, 98, 102);
			font-size: 14px;
			.cont{
				 display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow:ellipsis;
			}

			.icons {
				margin-left: 4px;
			}
		}
	}

	.u-config-wrap {
		padding: 40rpx;
	}

	.slot-content {
		background-color: #FFFFFF;
		padding: 24rpx;

		.item-box {
			margin-bottom: 50rpx;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;

			.item {
				border: 1px solid $u-type-primary;
				color: $u-type-primary;
				padding: 8rpx 40rpx;
				border-radius: 100rpx;
				margin-top: 30rpx;
			}

			.active {
				color: #FFFFFF;
				background-color: $u-type-primary;
			}
		}
	}
</style>
